<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <link href="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=BoDHWfB34TUhSDodZSudcbo0"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js"></script>
    <title>路况信息</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    var mapLng = -1;
    var mapLat = -1;
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(121.455,37.468722), 15);
    map.enableScrollWheelZoom(); // 允许滚轮缩放
    var ctrl = new BMapLib.TrafficControl({
        showPanel: true //是否显示路况提示面板
    });
    map.addControl(ctrl);
    ctrl.setAnchor(BMAP_ANCHOR_BOTTOM_RIGHT);

    var point = new BMap.Point(121.455,37.468722);



    //用户当前位置标注点；
    var userLocaMarker = new BMap.Marker(point, {icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT,{
        scale: 1,//图标缩放大小
        fillColor: "#3B71CC",//填充颜色
        fillOpacity: 1,//填充透明度
        strokeColor: "white",
        strokeOpacity: .9
    })});
    var showlocalInfo = false;
    var infoArray = new Array();
    var address = "";
    var userGeoc = new BMap.Geocoder();
    userLocaMarker.addEventListener("click", function localInfo(){
        var infoOverlay = new RouteInfoOverlay(userLocaMarker.getPosition(),address);
        map.addOverlay(infoOverlay);
        infoArray.push(infoOverlay);
        if(!showlocalInfo){
            showlocalInfo = true;
        }else {
            $.each(infoArray, function(i,n){
                map.removeOverlay(n);
            });
            showlocalInfo = false;
        }
    });

    //地图定位服务
    var geolocationControl = new BMap.GeolocationControl({
        anchor : BMAP_ANCHOR_TOP_RIGHT,
    });

    geolocationControl.addEventListener("locationError", function(e) {
        //alert("定位失败");
    });
    map.addControl(geolocationControl);

    var geolocation = new BMap.Geolocation();
    //alert("正在定位...")
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            userLocaMarker.setPosition(r.point);
            userGeoc.getLocation(r.point, function(res){
                address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
            });
            map.addOverlay(userLocaMarker);
            if(mapLng!="-1" && mapLat!="-1"){
                map.panTo(new BMap.Point(mapLng,mapLat))
                var objs = document.getElementsByName("search_condition");
                var mobj;
                $.each(objs, function(i,n){
                    if(n.innerText == searchName){
                        mobj = n;
                    }
                });
                search_2(searchName, searchID, mobj);
            }else{
                map.panTo(r.point);
            }
            g_lat = r.point.lat;
            g_lng = r.point.lng;
            //alert("定位成功");
        }else {
            //alert("定位失败");
        }
    }, {
        enableHighAccuracy : true
    });
</script>
